#!/bin/bash
cd /home/ebbflow

# Clean up
pkill -f test_buffering || true
sleep 1
rm -rf logs_buffering
mkdir -p logs_buffering

# Start 6 nodes
echo "Starting 6 nodes..."
for i in 0 1 2 3 4 5; do
    ./test_buffering $i > logs_buffering/node_$i.log 2>&1 &
    echo "Started node $i (PID: $!)"
done

# Wait for test completion
echo "Waiting 20 seconds for test..."
sleep 20

# Kill all nodes
pkill -f test_buffering || true
sleep 1

# Check results
echo ""
echo "=== Test Results ==="
for i in 1 2 3 4 5; do
    if grep -q "TEST PASSED" logs_buffering/node_$i.log; then
        echo "Node $i: ✅ PASSED"
    elif grep -q "TEST FAILED" logs_buffering/node_$i.log; then
        echo "Node $i: ❌ FAILED"
    else
        echo "Node $i: ⚠️  UNKNOWN"
    fi
done

echo ""
echo "=== Buffering Messages Summary ==="
for i in 0 1 2 3 4 5; do
    echo "Node $i:"
    grep -E "buffering|pending|Sending.*pending" logs_buffering/node_$i.log | head -3
done

